package com.yiwenup.leetcode.top_interview_150;

/**
 * 文件描述
 *
 * @Project struct-algorithm
 * @Package com.yiwenup.leetcode.top_interview_150
 * @Author yiwenup
 * @Date 2024-12-11 18:26:49
 * @Description https://leetcode.cn/problems/longest-substring-without-repeating-characters/description/?envType=study-plan-v2&envId=top-interview-150
 */
public class No0003 {
    public int lengthOfLongestSubstring(String s) {
        if(s.length() == 0) {
            return 0;
        }
        int left = 0;
        int maxLen = 1;
        for(int right = 1; right < s.length(); right++) {
            int scan = left;
            while(scan < right) {
                if(s.charAt(scan) == s.charAt(right)) {
                    left = scan + 1;
                    break;
                }
                scan++;
            }
            maxLen = Math.max(maxLen, right - left + 1);
        }
        return maxLen;
    }
}
